<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%-- <%@ taglib prefix="battcn" uri="http://www.battcn.com/tags"%> --%>
<script type="text/javascript">
  $(document).ready(function(){$(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",})});
  $(function(){
	  xf.admin.menu${OP.menuId}.save = function(obj) {
  		if($("#menu${OP.menuId}Form").valid()){
  			$.ajax({
				type: "POST", 
				url: rootPath + "/op_save_${OP.menuId}.do",
				data: $('#menu${OP.menuId}Form').serializeArray(),
				dataType: "json",
				success: function(data){
					if(data.success) {
						xf.closeWindow();
						$('#admin_menu${OP.menuId}_datagrid').bootstrapTable('refresh');
					}
					xf.toastrsAlert({
		       		     code: data.success ? 'success' :'error',
		       		     msg: data.msg
		       		});
				}
			});
  		}
	}
	 
	 xf.admin.menu${OP.menuId}.update = function(obj) {
  		if($("#menu${OP.menuId}Form").valid()){
  			$.ajax({
				type: "POST", 
				url: rootPath + "/op_update_${OP.menuId}.do",
				data: $('#menu${OP.menuId}Form').serializeArray(),
				dataType: "json",
				success: function(data){
					if(data.success) {
						xf.closeWindow();
						$('#admin_menu${OP.menuId}_datagrid').bootstrapTable('refresh');
					}
					xf.toastrsAlert({
		       		     code: data.success ? 'success' :'error',
		       		     msg: data.msg
		       		});
				}
			});
  		}
	}  
  });
  //--------------------------------------------------------------------------------------
 $(function(){
	  $("#menuContent").hide();
});
 //---------------------------------------------------------------------------------------- 
  var zNodes;
  var zTreeObj;
  var setting = {
//   	check: {
//   		enable: true,//显示checkbox
//   		chkStyle: "radio",
//   		radioType: "all"
//   	},
  	view : {
  		dblClickExpand: false
  	},
  	data: {
  		simpleData: {
			enable: true
		}
	},
  	callback: {
  		beforeClick: beforeClick,
  		onClick: onClick
	}
  };
  
$(function(){
	$.ajax({
		type: "POST", 
		url: rootPath + "/sysMenu/selectParentMenu.do",
		data: '',
		dataType: "json",
		success: function(data){
			zNodes=data;
		    zTreeObj = $.fn.zTree.init($("#menuRsTree"), setting, zNodes); 
		}
	  });
});

function beforeClick(treeId, treeNode) {
	var check = (treeNode && !treeNode.isParent);
	if (!check){
		xf.toastrsAlert({
		     code:'warning',
		     msg:'sorry , 不能选择父级菜单'
		});
	}
	return check;
}

function onClick(e, treeId, treeNode) {
	var zTree = $.fn.zTree.getZTreeObj("menuRsTree"),
	nodes = zTree.getSelectedNodes(),
	n = "";
	v = "";
	nodes.sort(function compare(a,b){return a.id-b.id;});
	for (var i=0, l=nodes.length; i<l; i++) {
		n += nodes[i].id;
		v += nodes[i].name + ",";
	}
	if (v.length > 0 ) v = v.substring(0, v.length-1);
	var menuId=$("#menuId");
	var menuName = $("#menuName2");
	menuId.attr("value",n);
	menuName.attr("value", v);
}

var showCount=0;
function showMenu() {
	if(showCount%2==0){
		$("#menuContent").show();
	}else{
		$("#menuContent").hide();
	}
	showCount++;
}
</script>

<div class="ibox float-e-margins animated fadeInRight">
	<div class="ibox-content">
		<form class="form-horizontal m-t required-validate"
			id="menu${OP.menuId}Form" action="op_save_${OP.menuId}.do"
			method="post">
			<input type="hidden" name="resourceId" value="${dto.resourceId}" />
			<input type="hidden" name="menuId" value="${dto.menuId}" id="menuId"/>
			<div class="form-group">
			    <label class="col-sm-3 control-label">菜单选择：</label>
			    <div class="col-sm-8">
					<input name="menuName" class="form-control" type="text" 
						value="${dto.menuName}" readonly onclick="showMenu();" id="menuName2">
				</div>
			</div>
			<div class="form-group">
			     <label class="col-sm-3 control-label"></label>
                 <div id="menuContent"  class="col-sm-8">
				      <ul id="menuRsTree" class="ztree"></ul>
			     </div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">资源名称：</label>
				<div class="col-sm-8">
					<input name="resourceName" class="form-control" type="text"
						value="${dto.resourceName}"
						validate="{required:true,messages:{required:'请填写姓名'}}">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">图标：</label>
				<div class="col-sm-8">
					<input name="icon" class="form-control" type="text"
						value="${dto.icon}">
				</div>
			</div>
		    <div class="form-group">
				<label class="col-sm-3 control-label">排序：</label>
				<div class="col-sm-8">
					<input name="level" class="form-control" type="text"
						value="${dto.level}">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">是否展示：</label>
				<div class="col-sm-8">
					<div class="radio i-checks radio-inline">
						<label> <input type="radio" value="00"
							<c:if test="${dto.isShow == '00'}"> checked</c:if> name="isShow">
							<i></i> 是
						</label>
					</div>
					<div class="radio i-checks    radio-inline">
						<label> <input type="radio"
							<c:if test="${dto.isShow == '10'}"> checked</c:if> value="10"
							name="isShow"> <i></i>否
						</label>
					</div>
				</div>
			</div>
			
		</form>
	</div>
	
</div>
